package cn.stronglink.asset.module.assetmanage.itasset.controller;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.IdWorker;

import cn.stronglink.asset.model.AssetBrand;
import cn.stronglink.asset.model.AssetExtMaintenance;
import cn.stronglink.asset.model.AssetExtUsing;
import cn.stronglink.asset.model.AssetModel;
import cn.stronglink.asset.model.AssetTypeAttr;
import cn.stronglink.asset.model.AssetTypeValue;
import cn.stronglink.asset.model.Department;
import cn.stronglink.asset.model.ItAsset;
import cn.stronglink.asset.model.ItAssetExtPosition;
import cn.stronglink.asset.model.TRoom;
import cn.stronglink.asset.model.User;
import cn.stronglink.asset.module.assetmanage.attrvalue.service.AttrValueService;
import cn.stronglink.asset.module.assetmanage.instock.service.PresetDetailService;
import cn.stronglink.asset.module.assetmanage.itasset.param.AssetExtPositionParam;
import cn.stronglink.asset.module.assetmanage.itasset.service.ItassetService;
import cn.stronglink.asset.module.assetmanage.itasset.vo.AssetExlVo;
import cn.stronglink.asset.module.assetmanage.itasset.vo.ItAssetVo;
import cn.stronglink.asset.module.assetmanage.itasset.vo.LightAssetVo;
import cn.stronglink.asset.module.basicdata.assetBrand.service.AssetBrandService;
import cn.stronglink.asset.module.basicdata.assetModel.service.AssetModelService;
import cn.stronglink.asset.module.basicdata.assetType.service.AssetTypeService;
import cn.stronglink.asset.module.basicdata.tRoom.service.TRoomService;
import cn.stronglink.asset.module.basicdata.tRoom.vo.RoomTreeNodeVo;
import cn.stronglink.suite.core.base.AbstractController;
import cn.stronglink.suite.core.config.Resources;
import cn.stronglink.suite.core.exception.BusinessException;
import cn.stronglink.suite.core.log.annotation.OperateLog;
import cn.stronglink.suite.core.log.annotation.OperateLog.OpType;
import cn.stronglink.suite.core.support.HttpCode;
import cn.stronglink.suite.core.util.BmUtils;
import cn.stronglink.suite.core.util.DownloadExcelUtil;
import cn.stronglink.suite.core.util.WebUtil;
import jxl.format.BorderLineStyle;

@Controller
@RequestMapping(value = "asset")
public class ItassetController extends AbstractController {

	@Autowired
	private ItassetService itassetService;
	@Autowired
	private TRoomService tRoomService;
	@Autowired
	private PresetDetailService presetDetailService;
	@Autowired
	private AssetTypeService assetTypeService;
	@Autowired
	private AssetModelService assetModelService;
	@Autowired
	private AssetBrandService assetBrandService;
	@Autowired
	private AttrValueService attrValueService;
	
	/**
	 * 导入EXCEL文件
	 * @param file
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "importAsset")
	public ResponseEntity<ModelMap> importAsset(@RequestParam(value = "file", required = true) MultipartFile file,HttpServletRequest request,
			HttpServletResponse response,ModelMap modelMap) throws Exception{
		//Long presetId =Long.parseLong(request.getParameter("presetId"));
		List<String> dataList=new ArrayList<String>();
		//导入Excel操作
		//导入Excel文件不为空时，将文件写入流，然后转化为工作薄
		if (file!=null){
			try {	
				Workbook workBook = null;
				String fileType = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1, file.getOriginalFilename().length());
				if(!"xls".equals(fileType)&&!"xlsx".equals(fileType)){
					throw new BusinessException("请选择excel格式文件！");
				}
				int header=0;
				workBook = WorkbookFactory.create(file.getInputStream());
				if (workBook.getNumberOfSheets()>0){
					//获取第一个单元薄
					Sheet sheet = workBook.getSheetAt(0);
					//获取单元薄中表头信息,并将表头中每个单元格中信息存入数组headNames中
					Long typeId = assetTypeService.getTypeIdByName(sheet.getSheetName());
					if (typeId==null) {
						throw new BusinessException("请使用模板文件！");
					}
					List<AssetTypeAttr> arrtValueList = itassetService.queryAttrByTypeId(typeId.toString());
					String fixedTitle = "资产编号$*设备序列号$*设备名称$*品牌$*设备型号$*RFID号$IP地址$*所在机房$*所在机柜$*起始U位$*结束U位$*是否为借用-(是/不是)$*是否分配-(未分配/分配)$领用部门-(若分配,则必填)$领用人-(若分配,则必填)$供货方$联系电话$联系人$售后电话$合同号$发票号$购置时间-(yyyy/MM/dd)$报修到期时间-(yyyy/MM/dd)";
					String dynamicTitle = "";
					if (arrtValueList!=null&&arrtValueList.size()>0) {
						StringBuffer sb = new StringBuffer();
						for (AssetTypeAttr assetTypeAttr : arrtValueList) {
							if (assetTypeAttr.getIsNotNull()!=null&&assetTypeAttr.getIsNotNull()) {
								sb.append("*");
							}
							sb.append(assetTypeAttr.getLable());
							if (assetTypeAttr.getType()!=null) {
								sb.append("-");
								if (assetTypeAttr.getType()==1) {
									sb.append("(文本类型)");
								}else if(assetTypeAttr.getType()==2){
									sb.append("(数值)");
								}else if(assetTypeAttr.getType()==3){
									sb.append("(多行文本)");
								}else if(assetTypeAttr.getType()==4){
									if (assetTypeAttr.getOptions()!=null) {
										sb.append("(下拉:("+assetTypeAttr.getOptions()+"))");
									}else {
										sb.append("下拉:(请检查设备属性！)");
									}
								}else if(assetTypeAttr.getType()==5){
									sb.append("(时间:yyyy/MM/dd)");
								}
							}
							if (assetTypeAttr.getDefValue()!=null&&!"".equals(assetTypeAttr.getDefValue())) {
								sb.append("-");
								sb.append("默认值:"+assetTypeAttr.getDefValue());
							}
							sb.append("$");
						}
						dynamicTitle = sb.toString().substring(0,sb.toString().length() - 1);
					}
					String finalTile = fixedTitle+"$"+dynamicTitle;
					Row rowHead = sheet.getRow(header); 
					if (rowHead != null) {
						String[] headNames = new String[rowHead.getLastCellNum()];
						// 获取该行中总共有多少列数据row.getLastCellNum()
						for (int j = 0; j < rowHead.getLastCellNum(); j++) {
							Cell cell = rowHead.getCell(j);
							if (cell == null) {
								continue;
							} else {
								// 获取表头各个字段名称
								String returnStr = BmUtils.getCellValue(cell);
								headNames[j] = returnStr;
							}
						}
						if (headNames!=null&&headNames.length>0) {
							for (String name : headNames) {
								if (finalTile.indexOf(name)==-1) {
									throw new BusinessException("请使用模板文件！");
								}
							}
						}
						List<ItAssetVo> assetlList = new ArrayList<ItAssetVo>();
						List<AssetTypeValue> attrValueList = new ArrayList<AssetTypeValue>();
						List<String> existAsset = itassetService.queryAllAssetNoList();//表中存在的assetNo
						List<String> existRFID = itassetService.queryAllAssetRFIDList();//表中存在的RFID
						List<AssetBrand> brandData = assetBrandService.queryAssetBrandList();//设备品牌列表
						List<AssetModel> modelData = assetModelService.queryListAllS();//设备型号列表
						List<TRoom> roomData = itassetService.queryRoomList();//机房列表
						List<ItAsset> rackData = itassetService.queryAllRackList();//机柜列表
						List<Department> departmentData = itassetService.queryAllDepartmentList();//部门列表
						List<User> userData = itassetService.queryAllUserList();//用户列表
						Date date = new Date();
						// 遍历单元簿中每一行，获取每一列字段，并根据表头对应赋值
						int flag=1;
						List<String> currentAssetNo = new ArrayList<String>();
						List<String> currentRFID = new ArrayList<String>();
						for (int i = header; i < sheet.getPhysicalNumberOfRows(); i++) {
							Row row = sheet.getRow(i + 1);
							Boolean isRow = isRowEmpty(row);
							ItAssetVo assetVo = null;
							if (!isRow) {
								String rowError="第"+flag+"行   ";
								String data="";
								assetVo = new ItAssetVo();
								assetVo.setTypeId(typeId);
								assetVo.setId(IdWorker.getId());
								assetVo.setCreateBy(WebUtil.getCurrentUser());
								assetVo.setCreateTime(date);
								assetVo.setIsBorrow(false);
								assetVo.setStatus(2);
								
								int assetExist=0;//assetNo是否重复
								int rfidExist=0;//assetRFID是否重复
								int assetNoR = 0;//assetNo在文档中是否重复
								int rfidR = 0;//assetRFID在文档中是否重复
								// 获取该行中总共有多少列数据row.getLastCellNum()
								for (int j = 0; j < row.getLastCellNum(); j++) {
									Cell cell = row.getCell(j);
									if (cell == null) {
										continue;
									} else if (StringUtils.hasText(headNames[j])) {
										// 获取单元格内容，并根据单元格类型，进行转化
										String returnStr = BmUtils.getCellValue(cell);
										// 根据给定的Excel格式，进行导入，一下是对应列对应字段
										if (headNames[j].equals("资产编号")) {
											if(returnStr!=null&&!"".equals(returnStr)){
												assetVo.setAssetNo(returnStr);
												assetExist=existAsset.contains(returnStr)?1:0;
												if (currentAssetNo!=null&&currentAssetNo.size()>0) {
													assetNoR=currentAssetNo.contains(returnStr)?1:0;
													currentAssetNo.add(returnStr);
												}else {
													currentAssetNo.add(returnStr);
												}
											}
										}else if (headNames[j].equals("*设备序列号")) {
											if(returnStr!=null&&!"".equals(returnStr)){
												assetVo.setSerialNo(returnStr);;
											}else{
												data += "设备序列号不能为空;";
											}
										} else if (headNames[j].equals("*设备名称")) {
											if(returnStr!=null&&!"".equals(returnStr)){
												assetVo.setAssetName(returnStr);
											}else{
												data += "设备名称不能为空;";
											}
										}else if (headNames[j].equals("*品牌")) {											
											if(returnStr!=null&&!returnStr.equals("")){
												if(brandData!=null &&brandData.size()>0){
													boolean isExit=false;
													for(AssetBrand brand : brandData){
														if(brand.getName().equals(returnStr)){
															assetVo.setBrandId(brand.getId());
															isExit=true;
															break;
														}
													}
													if(!isExit){
														data+="品牌不存在，请先添加品牌;";
													}
												}
												
											}else{
												data +=data==null||"".equals(data)?"品牌不能为空":";品牌不能为空;";
											}
										}else if (headNames[j].equals("*设备型号")) {											
											if(returnStr!=null&&!returnStr.equals("")){
												if(modelData!=null &&modelData.size()>0){
													boolean isExit=false;
													for(AssetModel model : modelData){
														if(model.getName().equals(returnStr)){
															if (assetVo.getBrandId()!=null&&assetVo.getTypeId()!=null) {
																if (model.getBrandId().equals(assetVo.getBrandId())&&model.getTypeId().equals(assetVo.getTypeId())) {
																	assetVo.setModelId(model.getId());
																	isExit=true;
																	break;
																}else {
																	data+="设备型号不属于此数据设备类型或品牌;";
																	isExit=true;
																	break;
																}
															}
														}
													}
													if(!isExit){
														data+="设备型号不存在，请先添加设备型号;";
													}
												}
											}else{
												data+="设备型号不能为空;";
											}
										}else if (headNames[j].equals("*RFID号")) {
												if(returnStr!=null&&!"".equals(returnStr)){
													assetVo.setRfidNo(returnStr);
													rfidExist=existRFID.contains(returnStr)?1:0;
													if (currentRFID!=null&&currentRFID.size()>0) {
														rfidR=currentRFID.contains(returnStr)?1:0;
														currentRFID.add(returnStr);
													}else {
														currentRFID.add(returnStr);
													}
												}
										}else if (headNames[j].equals("IP地址")) {
											assetVo.setIp(returnStr);
										}else if (headNames[j].equals("*所在机房")) {											
											if(returnStr!=null&&!returnStr.equals("")){
												if(roomData!=null &&roomData.size()>0){
													boolean isExit=false;
													for(TRoom room : roomData){
														if(room.getName().equals(returnStr)){
															assetVo.setRoomId(room.getId());
															isExit=true;
															break;
														}
													}
													if(!isExit){
														data+="机房不存在，请先添加机房;";
													}
												}
											}else{
												data +=data==null||"".equals(data)?"机房不能为空":";机房不能为空;";
											}
										}else if (headNames[j].equals("*所在机柜")) {											
											if(returnStr!=null&&!returnStr.equals("")){
												if(rackData!=null &&rackData.size()>0){
													boolean isExit=false;
													int last = 0;
													for(ItAsset rack : rackData){
														if(rack.getAssetName().equals(returnStr)){
															if (assetVo.getRoomId()!=null) {
																if (rack.getRoomId().equals(assetVo.getRoomId())) {
																	assetVo.setRackId(rack.getId());
																	isExit=true;
																	break;
																}else {
																	last++;
																	isExit=true;
																}
															}else {
																isExit=true;
																break;
															}
														}
													}
													if (assetVo.getRackId()==null&&last>0) {
														data+="机柜不属于此数据添加的机房;";
													}
													if(!isExit){
														data+="机柜不存在，请先添加机柜;";
													}
												}
											}else{
												data +=data==null||"".equals(data)?"机柜不能为空":";机柜不能为空;";
											}
										}else if (headNames[j].equals("*起始U位")) {
											if(returnStr!=null&&!"".equals(returnStr)){
												Boolean isNum = isNumeric(returnStr);
												if (isNum) {
													assetVo.setStartU(Integer.valueOf(returnStr));
												}else {
													data += "起始U位请填写数字;";
												}
											}else{
												data += "起始U位不能为空;";
											}
										}else if (headNames[j].equals("*结束U位")) {
											if(returnStr!=null&&!"".equals(returnStr)){
												Boolean isNum = isNumeric(returnStr);
												if (isNum) {
													assetVo.setEndU(Integer.valueOf(returnStr));
												}else {
													data += "结束U位请填写数字;";
												}
												
											}else{
												data += "结束U位不能为空;";
											}
										}else if (headNames[j].equals("*管理部门")) {
											if(returnStr!=null&&!returnStr.equals("")){
												if(departmentData!=null &&departmentData.size()>0){
													boolean isExit=false;
													for(Department d : departmentData){
														if(d.getName().equals(returnStr)){
															assetVo.setManageBranchId(d.getId());
															isExit=true;
															break;
														}
													}
													if(!isExit){
														data+="管理部门不存在，请先添加管理部门;";
													}
												}
											}else{
												data +=data==null||"".equals(data)?"管理部门不能为空":";管理部门不能为空;";
											}
										}else if (headNames[j].equals("*是否为借用-(是/不是)")) {
											if(returnStr!=null&&!"".equals(returnStr)){
												if ("是".equals(returnStr)) {
													assetVo.setIsBorrow(true);
												}else {
													assetVo.setIsBorrow(false);
												}
											}else{
												data += "是否为借用不能为空;";
											}
										}else if (headNames[j].equals("*是否分配-(未分配/分配)")) {
											if(returnStr!=null&&!"".equals(returnStr)){
												if ("分配".equals(returnStr)) {
													assetVo.setIsDistribute(true);
												}else {
													assetVo.setIsDistribute(false);
												}
											}else{
												data += "是否分配不能为空;";
											}
										}else if (headNames[j].equals("领用部门-(若分配,则必填)")) {		
											if (assetVo.getIsDistribute()) {
												if(returnStr!=null&&!returnStr.equals("")){
													if(departmentData!=null &&departmentData.size()>0){
														boolean isExit=false;
														for(Department d : departmentData){
															if(d.getName().equals(returnStr)){
																assetVo.setUseBranchId(d.getId());
																isExit=true;
																break;
															}
														}
														if(!isExit){
															data+="领用部门不存在，请先添加领用部门;";
														}
													}
												}else{
													data +=data==null||"".equals(data)?"领用部门不能为空":";领用部门不能为空;";
												}
											}
										}else if (headNames[j].equals("领用人-(若分配,则必填)")) {		
											if (assetVo.getIsDistribute()) {
												if(returnStr!=null&&!returnStr.equals("")){
													if(userData!=null &&userData.size()>0){
														boolean isExit=false;
														for(User user : userData){
															if(user.getName().equals(returnStr)){
																if (user.getDeptId().equals(assetVo.getUseBranchId())) {
																	assetVo.setEndUser(user.getId().toString());
																	isExit=true;
																	break;
																}else {
																	data+="领用人不属于此数据填写的部门;";
																	isExit=true;
																	break;
																}
																
															}
														}
														if(!isExit){
															data+="领用人不存在，请先添加领用人;";
														}
													}
												}else{
													data +=data==null||"".equals(data)?"领用人不能为空":";领用人不能为空;";
												}
											}
										}else if (headNames[j].equals("供货方")) {
											if(returnStr!=null&&!"".equals(returnStr)){
												assetVo.setSupplier(returnStr);
											}
										}else if (headNames[j].equals("联系电话")) {
											if(returnStr!=null&&!"".equals(returnStr)){
												assetVo.setContactsPhone(returnStr);
											}
										}else if (headNames[j].equals("联系人")) {
											if(returnStr!=null&&!"".equals(returnStr)){
												assetVo.setContacts(returnStr);
											}
										}else if (headNames[j].equals("售后电话")) {
											if(returnStr!=null&&!"".equals(returnStr)){
												assetVo.setHotline(returnStr);
											}
										}else if (headNames[j].equals("合同号")) {
											if(returnStr!=null&&!"".equals(returnStr)){
												assetVo.setContractNo(returnStr);
											}
										}else if (headNames[j].equals("发票号")) {
											if(returnStr!=null&&!"".equals(returnStr)){
												assetVo.setInvoiceNo(returnStr);
											}
										}else if (headNames[j].equals("购置时间-(yyyy/MM/dd)")) {
											if(returnStr!=null&&!"".equals(returnStr)){
												Boolean isTrue = isValidDate("yyyy/MM/dd",returnStr);
												if (isTrue) {
													SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
													assetVo.setBuyTime(sdf.parse(returnStr));
												}else {
													data+="购置时间格式不对;";
												}
												
											}
										}else if (headNames[j].equals("报修到期时间-(yyyy/MM/dd)")) {
											if(returnStr!=null&&!"".equals(returnStr)){
												Boolean isTrue = isValidDate("yyyy/MM/dd",returnStr);
												if (isTrue) {
													SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
													assetVo.setExpirationTime(sdf.parse(returnStr));
												}else {
													data+="报修到期时间格式不对;";
												}
												
											}
										}else {
											if (arrtValueList!=null&&arrtValueList.size()>0) {
												for (AssetTypeAttr arrt : arrtValueList) {
													if (headNames[j].indexOf(arrt.getLable())>-1) {
														String title = headNames[j];
														if (title.indexOf("*")>-1) {
															if(returnStr!=null&&!"".equals(returnStr)){
																if (arrt.getType()==1) {//文本
																	AssetTypeValue value = new AssetTypeValue();
																	value.setAssetId(assetVo.getId());
																	value.setAttrId(arrt.getId());
																	value.setCreateBy(WebUtil.getCurrentUser());
																	value.setId(IdWorker.getId());
																	value.setCreateTime(date);
																	value.setValue(returnStr);
																	attrValueList.add(value);
																}else if (arrt.getType()==2) {//数值
																	Boolean isNum = isNumeric(returnStr);
																	if (isNum) {
																		AssetTypeValue value = new AssetTypeValue();
																		value.setAssetId(assetVo.getId());
																		value.setAttrId(arrt.getId());
																		value.setCreateBy(WebUtil.getCurrentUser());
																		value.setId(IdWorker.getId());
																		value.setCreateTime(date);
																		value.setValue(returnStr.replace("/", "-"));
																		attrValueList.add(value);
																	}else {
																		data+=arrt.getLable()+"请使用数字格式;";
																	}
																}else if (arrt.getType()==3) {//多行文本
																	AssetTypeValue value = new AssetTypeValue();
																	value.setAssetId(assetVo.getId());
																	value.setAttrId(arrt.getId());
																	value.setCreateBy(WebUtil.getCurrentUser());
																	value.setId(IdWorker.getId());
																	value.setCreateTime(date);
																	value.setValue(returnStr);
																	attrValueList.add(value);
																}else if (arrt.getType()==4) {//下拉
																	if (title.indexOf(returnStr)>0) {
																		AssetTypeValue value = new AssetTypeValue();
																		value.setAssetId(assetVo.getId());
																		value.setAttrId(arrt.getId());
																		value.setCreateBy(WebUtil.getCurrentUser());
																		value.setId(IdWorker.getId());
																		value.setCreateTime(date);
																		value.setValue(returnStr);
																		attrValueList.add(value);
																	}else {
																		data+=arrt.getLable()+"请使用已填写选项;";
																	}
																}else if (arrt.getType()==5) {//时间
																	Boolean isTrue = isValidDate("yyyy/MM/dd",returnStr);
																	if (isTrue) {
																		AssetTypeValue value = new AssetTypeValue();
																		value.setAssetId(assetVo.getId());
																		value.setAttrId(arrt.getId());
																		value.setCreateBy(WebUtil.getCurrentUser());
																		value.setId(IdWorker.getId());
																		value.setCreateTime(date);
																		value.setValue(returnStr.replace("/", "-"));
																		attrValueList.add(value);
																	}else {
																		data+=arrt.getLable()+"时间格式不正确;";
																	}
																}
																
															}else {
																data+=arrt.getLable()+"不能为空;";
															}
														}else {
															if(returnStr!=null&&!"".equals(returnStr)){
																if (arrt.getType()==1) {//文本
																	AssetTypeValue value = new AssetTypeValue();
																	value.setAssetId(assetVo.getId());
																	value.setAttrId(arrt.getId());
																	value.setCreateBy(WebUtil.getCurrentUser());
																	value.setId(IdWorker.getId());
																	value.setCreateTime(date);
																	value.setValue(returnStr);
																	attrValueList.add(value);
																}else if (arrt.getType()==2) {//数值
																	Boolean isNum = isNumeric(returnStr);
																	if (isNum) {
																		AssetTypeValue value = new AssetTypeValue();
																		value.setAssetId(assetVo.getId());
																		value.setAttrId(arrt.getId());
																		value.setCreateBy(WebUtil.getCurrentUser());
																		value.setId(IdWorker.getId());
																		value.setCreateTime(date);
																		value.setValue(returnStr.replace("/", "-"));
																		attrValueList.add(value);
																	}else {
																		data+=arrt.getLable()+"请使用数字格式;";
																	}
																}else if (arrt.getType()==3) {//多行文本
																	AssetTypeValue value = new AssetTypeValue();
																	value.setAssetId(assetVo.getId());
																	value.setAttrId(arrt.getId());
																	value.setCreateBy(WebUtil.getCurrentUser());
																	value.setId(IdWorker.getId());
																	value.setCreateTime(date);
																	value.setValue(returnStr);
																	attrValueList.add(value);
																}else if (arrt.getType()==4) {//下拉
																	if (title.indexOf(returnStr)>0) {
																		AssetTypeValue value = new AssetTypeValue();
																		value.setAssetId(assetVo.getId());
																		value.setAttrId(arrt.getId());
																		value.setCreateBy(WebUtil.getCurrentUser());
																		value.setId(IdWorker.getId());
																		value.setCreateTime(date);
																		value.setValue(returnStr);
																		attrValueList.add(value);
																	}else {
																		data+=arrt.getLable()+"请使用已填写选项;";
																	}
																}else if (arrt.getType()==5) {//时间
																	Boolean isTrue = isValidDate("yyyy/MM/dd",returnStr);
																	if (isTrue) {
																		AssetTypeValue value = new AssetTypeValue();
																		value.setAssetId(assetVo.getId());
																		value.setAttrId(arrt.getId());
																		value.setCreateBy(WebUtil.getCurrentUser());
																		value.setId(IdWorker.getId());
																		value.setCreateTime(date);
																		value.setValue(returnStr.replace("/", "-"));
																		attrValueList.add(value);
																	}else {
																		data+=arrt.getLable()+"时间格式不正确;";
																	}
																}
															}
														}
													}
												}
											}
										}     
										
									}
								}
								flag++;
								// 判断当前资产数据是否存在
								if (rfidR==0&assetNoR==0&&assetExist==0&&rfidExist==0) {
									assetlList.add(assetVo);
								}else{
									if (assetExist==1) {
										data += "资产编号"+assetVo.getAssetNo()+"已经存在;";
									}
									if (assetNoR==1) {
										data += "资产编号在导入文件中重复;";
									}
									if (rfidExist==1) {
										data += "RFID号"+assetVo.getRfidNo()+"已经存在;";
									}
									if (rfidR==1) {
										data += "RFID号在导入文件中重复;";
									}
									
								}
								if(data!=null&&!"".equals(data)){
//									if(dataList==null||dataList.size()==0){
//										dataList.add(rowError);
//									}
									dataList.add(rowError);
									dataList.add(data);
								}
							}
						}
						if(dataList!=null&&dataList.size()>0){
							String data="";
							for(String errorData:dataList){
								data+=errorData;
							}
							throw new BusinessException(data);
						}else{
							//存数据
							List<ItAssetExtPosition> extPositonList = new ArrayList<ItAssetExtPosition>();
							List<AssetExtUsing> extUsingList = new ArrayList<AssetExtUsing>();
							List<AssetExtMaintenance> extMaintenanceList = new ArrayList<AssetExtMaintenance>();
							if(assetlList != null && assetlList.size() > 0) {
								for (ItAssetVo assetVo : assetlList) {
									ItAssetExtPosition position = new ItAssetExtPosition();
									position.setId(IdWorker.getId());
									position.setAssetId(assetVo.getId());
									position.setRoomId(assetVo.getRoomId());
									position.setRackId(assetVo.getRackId());
									position.setStart(assetVo.getStartU());
									position.setEnd(assetVo.getEndU());
									position.setCreateTime(assetVo.getCreateTime());
									position.setCreateBy(assetVo.getCreateBy());
									extPositonList.add(position);
									if (assetVo.getIsDistribute()) {
										AssetExtUsing using = new AssetExtUsing();
										using.setId(IdWorker.getId());
										using.setAssetId(assetVo.getId());
										using.setCreateBy(assetVo.getCreateBy());
										using.setCreateTime(assetVo.getCreateTime());
										using.setManageBranchId(assetVo.getManageBranchId());
										using.setUseBranchId(assetVo.getUseBranchId());
										using.setEndUser(Long.valueOf(assetVo.getEndUser()));
										extUsingList.add(using);
									}
									if (assetVo.getSupplier()!=null
										||assetVo.getContactsPhone()!=null
										||assetVo.getContacts()!=null
										||assetVo.getHotline()!=null
										||assetVo.getContractNo()!=null
										||assetVo.getInvoiceNo()!=null
										||assetVo.getBuyTime()!=null
										||assetVo.getExpirationTime()!=null) {
										AssetExtMaintenance maintenance = new AssetExtMaintenance();
										maintenance.setId(IdWorker.getId());
										maintenance.setAssetId(assetVo.getId());
										maintenance.setCreateBy(assetVo.getCreateBy());
										maintenance.setCreateTime(assetVo.getCreateTime());
										if (assetVo.getSupplier()!=null) {
											maintenance.setSupplier(assetVo.getSupplier());
										}
										if (assetVo.getContactsPhone()!=null) {
											maintenance.setContactsPhone(assetVo.getContactsPhone());
										}
										if (assetVo.getContacts()!=null) {
											maintenance.setContacts(assetVo.getContacts());
										}
										if (assetVo.getHotline()!=null) {
											maintenance.setHotline(assetVo.getHotline());
										}
										if (assetVo.getContractNo()!=null) {
											maintenance.setContractNo(assetVo.getContractNo());
										}
										if (assetVo.getInvoiceNo()!=null) {
											maintenance.setInvoiceNo(assetVo.getInvoiceNo());
										}
										if (assetVo.getBuyTime()!=null) {
											maintenance.setBuyTime(assetVo.getBuyTime());
										}
										if (assetVo.getExpirationTime()!=null) {
											maintenance.setExpirationTime(assetVo.getExpirationTime());
										}
										extMaintenanceList.add(maintenance);
									}
								}
								//TODO 数据存储assetlList   extPositonList  extUsingList  extMaintenanceList  attrValueList
								itassetService.exportEXLDate(assetlList,extPositonList,extUsingList,extMaintenanceList,attrValueList);
								return setSuccessModelMap(modelMap);
							} else {
								throw new BusinessException("文件数据为空!");
							}
						}
						
					}
				}
			}catch (IOException e) {
				throw new BusinessException("未知异常!");
			}
		}
		throw new BusinessException("无文件!");
	}
	
	public static boolean isNumeric(String str){
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if( !isNum.matches() ){
            return false;
        }
        return true;
 }
	
	public static boolean isValidDate(String datePattern,String str) {
	      boolean convertSuccess=true;
	       SimpleDateFormat format = new SimpleDateFormat(datePattern);
	       try {
	          format.setLenient(false);
	          format.parse(str);
	       } catch (Exception e) {
	           convertSuccess=false;
	       } 
	       return convertSuccess;
	}
	
	public static boolean isRowEmpty(Row row) {
		if (row==null) {
			return true;
		}else {
			for (int c = row.getFirstCellNum(); c < row.getLastCellNum(); c++) {
			       Cell cell = row.getCell(c);
			       if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK)
			           return false;
			   }
			   return true;
		}
		}
	
	@RequestMapping(value = "downLoadEXLModel")
	public String downLoadEXLModel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String p = request.getParameter("param").toString();
		String param = new String(p.getBytes("ISO8859-1"), "UTF-8");
		Map<String, Object> params =  JSON.parseObject(param, Map.class);
		String typeName = itassetService.queryTypeNameByTypeId(params.get("typeId").toString());
		String fixedTitle = "资产编号$*设备序列号$*设备名称$*品牌$*设备型号$*RFID号$IP地址$*所在机房$*所在机柜$*起始U位$*结束U位$*是否为借用-(是/不是)$*是否分配-(未分配/分配)$领用部门-(若分配,则必填)$领用人-(若分配,则必填)$供货方$联系电话$联系人$售后电话$合同号$发票号$购置时间-(yyyy/MM/dd)$报修到期时间-(yyyy/MM/dd)";
		List<AssetTypeAttr> arrtValueList = itassetService.queryAttrByTypeId(params.get("typeId").toString());
		String finalTileS = fixedTitle;
		if (arrtValueList!=null&&arrtValueList.size()>0) {
			StringBuffer sb = new StringBuffer();
			for (AssetTypeAttr assetTypeAttr : arrtValueList) {
				if (assetTypeAttr.getIsNotNull()!=null&&assetTypeAttr.getIsNotNull()) {
					sb.append("*");
				}
				sb.append(assetTypeAttr.getLable());
				if (assetTypeAttr.getType()!=null) {
					sb.append("-");
					if (assetTypeAttr.getType()==1) {
						sb.append("(文本类型)");
					}else if(assetTypeAttr.getType()==2){
						sb.append("(数值)");
					}else if(assetTypeAttr.getType()==3){
						sb.append("(多行文本)");
					}else if(assetTypeAttr.getType()==4){
						if (assetTypeAttr.getOptions()!=null) {
							sb.append("(下拉:("+assetTypeAttr.getOptions()+"))");
						}else {
							sb.append("下拉:(请检查设备属性！)");
						}
					}else if(assetTypeAttr.getType()==5){
						sb.append("(时间:yyyy/MM/dd)");
					}
				}
				if (assetTypeAttr.getDefValue()!=null&&!"".equals(assetTypeAttr.getDefValue())) {
					sb.append("-");
					sb.append("默认值:"+assetTypeAttr.getDefValue());
				}
				sb.append("$");
			}
			String dynamicTitle = sb.toString().substring(0,sb.toString().length() - 1);
			finalTileS = finalTileS+"$"+dynamicTitle;
		}
		String[] titleArray = finalTileS.split("\\$");
		DownloadExcelUtil dExlUtile = new DownloadExcelUtil(response,"资产导入模板",typeName);
		dExlUtile.addRow(titleArray, BorderLineStyle.THIN,jxl.format.Alignment.CENTRE, "bold");
		dExlUtile.reportExcel();
		return null;
	}
	
	@RequestMapping(value = "downLoadEXL")
	public String downLoadEXL(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		//取出带查询条件的所有数据allList
		String p = request.getParameter("param").toString();
		String param = new String(p.getBytes("ISO8859-1"), "UTF-8");
		Map<String, Object> params =  JSON.parseObject(param, Map.class);
		List<ItAssetVo> allList = itassetService.queryAssetListNoPage(params);
		if (allList!=null&&allList.size()>0) {
			//根据typeId去重，查出type的ID和name，此为sheet
			List<Long> typeIdList = new ArrayList<Long>();
			for (ItAssetVo itAssetVo : allList) {
				if (!typeIdList.contains(itAssetVo.getTypeId())) {
					typeIdList.add(itAssetVo.getTypeId());
				}
			}
			if (typeIdList!=null&&typeIdList.size()>0) {
				//循环sheet
				int typeNum = 1;
				DownloadExcelUtil dExlUtile = null;
				for (Long typeId : typeIdList) {
					int dataNum = 1;
					for (ItAssetVo itAssetVo : allList) {
						if (itAssetVo.getTypeId().equals(typeId)) {//判断allList的type，相等继续
							//设置对象：title，value ，List<entity>
							StringBuffer sb = new StringBuffer();
							sb.append("资产编号_");
							sb.append(itAssetVo.getAssetNo()!=null?itAssetVo.getAssetNo():"-");
							sb.append("$");
							sb.append("设备序列号_");
							sb.append(itAssetVo.getSerialNo()!=null?itAssetVo.getSerialNo():"-");
							sb.append("$");
							sb.append("资产分类_");
							sb.append(itAssetVo.getTypeName()!=null?itAssetVo.getTypeName():"-");
							sb.append("$");
							sb.append("设备名称_");
							sb.append(itAssetVo.getAssetName()!=null?itAssetVo.getAssetName():"-");
							sb.append("$");
							sb.append("品牌_");
							sb.append(itAssetVo.getBrandName()!=null?itAssetVo.getBrandName():"-");
							sb.append("$");
							sb.append("设备型号_");
							sb.append(itAssetVo.getModelName()!=null?itAssetVo.getModelName():"-");
							sb.append("$");
							sb.append("RFID号_");
							sb.append(itAssetVo.getRfidNo()!=null?itAssetVo.getRfidNo():"-");
							sb.append("$");
							sb.append("所在机房_");
							sb.append(itAssetVo.getRoomName()!=null?itAssetVo.getRoomName():"-");
							sb.append("$");
							sb.append("所在位置_");
							sb.append(itAssetVo.getRackName()!=null?itAssetVo.getRackName():"-");
							sb.append("$");
							sb.append("U位_");
							sb.append(itAssetVo.getStartU()!=null?itAssetVo.getStartU():"-");
							sb.append("-");
							sb.append(itAssetVo.getEndU()!=null?itAssetVo.getEndU():"-");
							sb.append("$");
							sb.append("状态_");
							sb.append(itAssetVo.getStatus()!=null?itAssetVo.getStatus()==1?"在库":itAssetVo.getStatus()==2?"已上架":itAssetVo.getStatus()==3?"已报废":"-":"-");
							sb.append("$");
							sb.append("是否借用_");
							sb.append(itAssetVo.getIsBorrow()!=null?itAssetVo.getIsBorrow()?"借用":"未借用":"-");
							sb.append("$");
							sb.append("是否分配_");
							sb.append(itAssetVo.getIsDistribute()!=null?itAssetVo.getIsDistribute()?"已分配":"未分配":"-");
							sb.append("$");
							sb.append("管理部门_");
							sb.append(itAssetVo.getManageBranchName()!=null?itAssetVo.getManageBranchName():"-");
							sb.append("$");
							sb.append("领用部门_");
							sb.append(itAssetVo.getBranchName()!=null?itAssetVo.getBranchName():"-");
							sb.append("$");
							sb.append("领用人_");
							sb.append(itAssetVo.getUserName()!=null?itAssetVo.getUserName():"-");
							String tvsb = sb.toString();
							String[] tvsbArray = tvsb.split("\\$");
							List<AssetExlVo> entityList = new ArrayList<AssetExlVo>();
							if (tvsbArray.length>0) {
								for (String tv : tvsbArray) {
									AssetExlVo entity = new AssetExlVo();
									String[] tvArray = tv.split("_");
									entity.setTitle(tvArray[0]);
									entity.setValue(tvArray.length==1?"-":tvArray[1]);
									entityList.add(entity);
								}
							}
							//根据typeid和assetId,查询typeAttrLable和assetTypeValue
							//加入到当前的List<entity>中
							List<AssetExlVo> arrtValueList = itassetService.queryAttrVlaueByTypeIdAndAssetId(itAssetVo.getTypeId(),itAssetVo.getId());
							if (arrtValueList!=null&&arrtValueList.size()>0) {
								for (AssetExlVo assetExlVo : arrtValueList) {
									if (assetExlVo.getValue()==null||"".equals(assetExlVo.getValue())) {
										assetExlVo.setValue("-");
									}
								}
								entityList.addAll(arrtValueList);
							}
							if (typeNum == 1) {//当前type为第一个时
								if (dataNum == 1) {//若为第一次循环
									//在response中写入exl。传入当前type的name，和文件名：DownloadExcelUtil
									dExlUtile = new DownloadExcelUtil(response,"资产明细报表",itAssetVo.getTypeName());
									//把list<entity>中的title按list的顺序放入String【】，调用：setExcelListTitle
									String[] titleArray = new String[entityList.size()];
									for (int i = 0; i < entityList.size(); i++) {
										titleArray[i] = entityList.get(i).getTitle();
									}
									dExlUtile.addRow(titleArray, BorderLineStyle.THIN,jxl.format.Alignment.CENTRE, "bold");
									//dExlUtile.setExcelListTitle(titleArray);
									//把list<entity>中的value按list的顺序放入String【】，调用：addRow
									String[] valueArray = new String[entityList.size()];
									for (int i = 0; i < entityList.size(); i++) {
										valueArray[i] = entityList.get(i).getValue();
									}
									dExlUtile.addRow(valueArray, BorderLineStyle.THIN,jxl.format.Alignment.CENTRE, "");
								}else {
									//把list<entity>中的value按list的顺序放入String【】，调用：addRow
									String[] valueArray = new String[entityList.size()];
									for (int i = 0; i < entityList.size(); i++) {
										valueArray[i] = entityList.get(i).getValue();
									}
									dExlUtile.addRow(valueArray, BorderLineStyle.THIN,jxl.format.Alignment.CENTRE, "");
								}									
							}else {//type不为第一个时
								if (dataNum == 1) {//若为第一次循环
									//当前type的name：addSheet
									dExlUtile.addSheet(itAssetVo.getTypeName());
									//把list<entity>中的title按list的顺序放入String【】，调用：setExcelListTitle
									String[] titleArray = new String[entityList.size()];
									for (int i = 0; i < entityList.size(); i++) {
										titleArray[i] = entityList.get(i).getTitle();
									}
									dExlUtile.setExcelListTitle(titleArray);
									//把list<entity>中的value按list的顺序放入String【】，调用：addRow
									String[] valueArray = new String[entityList.size()];
									for (int i = 0; i < entityList.size(); i++) {
										valueArray[i] = entityList.get(i).getValue();
									}
									dExlUtile.addRow(valueArray, BorderLineStyle.THIN,jxl.format.Alignment.CENTRE, "");
								}else {
									//把list<entity>中的value按list的顺序放入String【】，调用：addRow
									String[] valueArray = new String[entityList.size()];
									for (int i = 0; i < entityList.size(); i++) {
										valueArray[i] = entityList.get(i).getValue();
									}
									dExlUtile.addRow(valueArray, BorderLineStyle.THIN,jxl.format.Alignment.CENTRE, "");
								}	
							}
							dataNum++;
						}
					}
					typeNum++;
				}
				dExlUtile.reportExcel();
				//dExlUtile.close();
			}
			
		}else {
			//查询结果为空
		}
		return null;
	}
	
	
	/**
	 * 查询资产列表（资产卡片功能）
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "queryAssetList")
	public ResponseEntity<ModelMap> queryAssetList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Map<String, Object> params) {	
		@SuppressWarnings("unchecked")
		Page<ItAssetVo> page = (Page<ItAssetVo>) super.getPage(params);
		long arrtValueStart = System.currentTimeMillis();
		Page<ItAssetVo> data = itassetService.queryAssetList(page,params);
		System.out.println("查询end use time:" + (System.currentTimeMillis() - arrtValueStart));
		return setSuccessModelMap(modelMap, data);
	}
	
	@RequestMapping(value = "qryAssetById")
	public ResponseEntity<ModelMap> qryAssetById(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Long assetId) {	
		ItAssetVo data = itassetService.qryAssetById(assetId);
		return setSuccessModelMap(modelMap, data);
	}
	/**
	 * 查看设备详情
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param assetId
	 * @return
	 */
	@RequestMapping(value = "qryAssetDetailById")
	public ResponseEntity<ModelMap> qryAssetDetailById(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Long assetId) {	
		ItAssetVo data = itassetService.qryAssetDetailById(assetId);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 查看设备详情并回显
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param assetId
	 * @return
	 */
	@RequestMapping(value = "qryDetailById")
	public ResponseEntity<ModelMap> qryDetailById(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Long assetId) {	
		ItAssetVo data = attrValueService.qryAssetAllAttrById(assetId);
		return setSuccessModelMap(modelMap, data);
	}
	
	@RequestMapping(value = "queryPresetList")
	public ResponseEntity<ModelMap> queryList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Map<String, Object> params) {	
		@SuppressWarnings("unchecked")
		Page<ItAsset> page = (Page<ItAsset>) super.getPage(params);
		Page<ItAsset> data = itassetService.queryList(page,params);
		return setSuccessModelMap(modelMap, data);
	}
	
	@RequestMapping(value = "qryById")
	public ResponseEntity<ModelMap> qryById(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Long id) {		
		ItAsset data = itassetService.qryById(id);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 到货验收
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param asset
	 * @return
	 */
	@OperateLog(module = "到货验收",desc="到货验收信息", type = OpType.UPDATE)
	@RequestMapping(value = "doCheck")
	public ResponseEntity<ModelMap> doCheck(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody AssetExtPositionParam asset) {
		//判断rfid是否存在
		if(!"".equals(asset.getRfidNo())&&asset.getRfidNo()!=null) {
			Boolean flag= presetDetailService.checkRfidNo(asset.getRfidNo(),asset.getId(),asset.getPresetDetailId());
			if(flag){		
				return setModelMap(modelMap, HttpCode.CONFLICT, Resources.getMessage("RFIDNO_EXIST"));
			}
		}
		if(!"".equals(asset.getSerialNo())&&asset.getSerialNo()!=null) {
			Boolean snFlag= presetDetailService.checkSn(asset.getSerialNo(),asset.getPresetDetailId());
			if(snFlag){		
				return setModelMap(modelMap, HttpCode.CONFLICT, Resources.getMessage("SERIALNO_EXIST"));
			}
		}
		
		if (asset.getAssetNo()!=null&&!"".equals(asset.getAssetNo())) {
			Integer assetNoNum = presetDetailService.checkAssetNoNum(asset.getAssetNo(),asset.getPresetDetailId());
			if (assetNoNum>0) {
				return setModelMap(modelMap, HttpCode.CONFLICT, "资产编号已经存在");
			}
		}
		itassetService.createItAsset(asset);
		return setSuccessModelMap(modelMap, null);
	}
	
	/**
	 * 修改资产属性
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param assetTypeValue
	 * @return
	 */
	@OperateLog(module = "资产卡片",desc="修改设备信息", type = OpType.UPDATE)
	@RequestMapping(value = "edit")
	public ResponseEntity<ModelMap> updateAttrValue(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody AssetTypeValue assetTypeValue) {		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("serialNo", assetTypeValue.getValues().getSerialNo());
		map.put("assetId", assetTypeValue.getAssetId());
		Boolean flag =itassetService.existsSerialNo(map);
		if(flag){
			return setModelMap(modelMap, HttpCode.CONFLICT, Resources.getMessage("SERIALNO_EXIST"));
		}
		
		//判断rfid是否存在
		Map<String, Object> rfidNoMap = new HashMap<String, Object>();
		rfidNoMap.put("rfidNo", assetTypeValue.getValues().getRfidNo());
		rfidNoMap.put("assetId", assetTypeValue.getAssetId());
		Integer count= itassetService.qryByRfidNo(rfidNoMap);
		if(count > 0){		
			return setModelMap(modelMap, HttpCode.CONFLICT, Resources.getMessage("RFIDNO_EXIST"));
		}
		//判断资产编号是否存在
		Map<String, Object> assetNoMap = new HashMap<String, Object>();
		assetNoMap.put("assetNo", assetTypeValue.getValues().getAssetNo());
		assetNoMap.put("assetId", assetTypeValue.getAssetId());
		Integer countNo= itassetService.qryByAssetNo(assetNoMap);
		if(countNo > 0){		
			return setModelMap(modelMap, HttpCode.CONFLICT, Resources.getMessage("RFIDNO_EXIST"));
		}		
				
		itassetService.editAssetInfo(assetTypeValue);
		return setSuccessModelMap(modelMap, null);
	}
	
	@OperateLog(module = "资产卡片",desc="删除资产信息", type = OpType.DEL)
	@RequestMapping(value = "remove")
	public ResponseEntity<ModelMap> remove(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Long id) {
		itassetService.removeItAsset(id);
		return setSuccessModelMap(modelMap, null);
	}

	/**
	 * 所在机房,设备类型,品牌,设备名称模糊查找资产
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "querAssetListByParam")
	public ResponseEntity<ModelMap> querAssetListByParam(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Map<String, Object> params) {	
		@SuppressWarnings("unchecked")
		Page<ItAssetVo> page = (Page<ItAssetVo>) super.getPage(params);
		Page<ItAssetVo> data = itassetService.querAssetListByParam(page,params);
		return setSuccessModelMap(modelMap, data);
	}
	/**
	 * 所在机房,设备类型,品牌,设备名称模糊查找资产(入库单模块)
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "qryAssetByParamInstock")
	public ResponseEntity<ModelMap> qryAssetByParamInstock(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Map<String, Object> params) {	
		@SuppressWarnings("unchecked")
		Page<ItAssetVo> page = (Page<ItAssetVo>) super.getPage(params);
		Page<ItAssetVo> data = itassetService.qryAssetByParamInstock(page,params);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 查询所有机柜
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "queryRackList")
	public ResponseEntity<ModelMap> queryDetailList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Long roomId) {	
		List<ItAsset> data = itassetService.queryRackList(roomId);
		Integer roomType = tRoomService.getRoomType(roomId);
		modelMap.put("roomType", roomType);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 查询该机房下所有机柜
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "qryRackTree")
	public ResponseEntity<ModelMap> qryRackTree(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Long roomId) {	
		List<RoomTreeNodeVo> data = itassetService.qryRackTree(roomId);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 判断这个资产序列化是否存在
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "checkSerialNo")
	public ResponseEntity<ModelMap> existsMsn(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Map<String, Object> params) {	
		Boolean count = itassetService.existsSerialNo(params);
		return setSuccessModelMap(modelMap, count);
	}

	
	/**
	 * 点亮设备（京东）
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param rfidNo
	 * @return
	 */
	@OperateLog(module = "资产卡片",desc="点亮标签", type = OpType.UPDATE)
	@RequestMapping(value = "onLightJd")
	public ResponseEntity<ModelMap> onLightJd(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody LightAssetVo param) {	
		long timestemp = System.currentTimeMillis();
		itassetService.onLightJd(param,timestemp);
		return setSuccessModelMap(modelMap, timestemp);
	}
	
	/**
	 * 取消点亮设备（京东）
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param rfidNo
	 * @return
	 */
	@OperateLog(module = "资产卡片",desc="取消点亮", type = OpType.UPDATE)
	@RequestMapping(value = "cancleLightJd")
	public ResponseEntity<ModelMap> cancleLightJd(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody LightAssetVo param) {	
		long timestemp = System.currentTimeMillis();
		itassetService.cancleLightJd(param,timestemp);
		return setSuccessModelMap(modelMap, timestemp);
	}
	
	/**
	 * 川庆点亮设备
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param rfidNo
	 * @return
	 */
	@OperateLog(module = "资产卡片",desc="点亮标签", type = OpType.UPDATE)
	@RequestMapping(value = "onLight")
	public ResponseEntity<ModelMap> onLight(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody String rfidNo) {	
		Boolean count = itassetService.onLight(rfidNo);
		return setSuccessModelMap(modelMap, count);
	}
	
	/**
	 * 川庆取消点亮设备
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param rfidNo
	 * @return
	 */
	@OperateLog(module = "资产卡片",desc="取消点亮", type = OpType.UPDATE)
	@RequestMapping(value = "cancleLight")
	public ResponseEntity<ModelMap> cancleLight(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody String rfidNo) {	
		Boolean count = itassetService.cancleLight(rfidNo);
		return setSuccessModelMap(modelMap, count);
	}
	
//	public static void main(String[] args) {
//		// 35 45 luru
//		// 30 40 yuan shi    true就是ｚｈａｎｙｏｎｇ
//		if(((30<=35 && 35<=40) || (30<=45 && 45<=40)) || ((35<=30 && 30<=45) || (35<=40 && 40<=45))){
//			System.out.println("fase");
//		}else{
//			System.out.println("true");
//		}
//	}
//	
	
	
}
